﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DataAccess;
using Model;
using Model.EntityModel;

namespace Project
{
    /// <summary>
    /// Interaction logic for PrintComplaintPart2.xaml
    /// </summary>
    public partial class PrintComplaintPart2 : UserControl
    {
        private long ComplaintId ;
        public PrintComplaintPart2(long complaintId)
        {
            ComplaintId = complaintId;
            InitializeComponent();
            SetComplaintInfo();
            LoadInformation();
        }

        private void SetComplaintInfo()
        {
            var complaint = ComplaintDataAccess.GetComplaintById(ComplaintId);
            tbIncidentDetail.Text = complaint.IncidentDetail;
            lblIncidentPlace.Content = complaint.IncidentPlace;
            lblIncidentZone.Content = complaint.IncidentZone;
            dateIncident.Content = complaint.IncidentDate.Value.ToShortDateString();
            SetViolenceCauses(complaint);
            SetViolenceForms(complaint);
            SetMultidisciplinaryTeam(complaint);
            SetCaseDerivations(complaint);
            if (complaint.CasesAttention == "Citacion Y Arresto")
            {
                chkArrest.IsChecked = true;
                chkMeeting.IsChecked = true;
            }
            if (complaint.CasesAttention == "Arresto")
            {
                chkArrest.IsChecked = true;
            }
            if (complaint.CasesAttention == "Citacion")
            {
                chkMeeting.IsChecked = true;
            }
        }

        private void SetViolenceCauses(Complaint complaint)
        {
            foreach (var violenceCause in complaint.ViolenceCause)
            {
                if (chkEconomics.Content.ToString() == violenceCause.Cause)
                    chkEconomics.IsChecked = true;
                if (chkFamiliar.Content.ToString() == violenceCause.Cause)
                    chkFamiliar.IsChecked = true;
                if (chkJealous.Content.ToString() == violenceCause.Cause)
                    chkJealous.IsChecked = true;
                if (chkInfidelity.Content.ToString() == violenceCause.Cause)
                    chkInfidelity.IsChecked = true;
                if (chkOthersNature.Content.ToString() == violenceCause.Cause)
                    chkOthersNature.IsChecked = true;
                if (chkDomainHabits.Content.ToString() == violenceCause.Cause)
                    chkDomainHabits.IsChecked = true;
            }
        }

        private void SetViolenceForms(Complaint complaint)
        {
            foreach (var violenceForm in complaint.ViolenceForm)
            {
                if (chkPhysics.Content.ToString() == violenceForm.Form)
                    chkPhysics.IsChecked = true;
                if (chkPsicologics.Content.ToString() == violenceForm.Form)
                    chkPsicologics.IsChecked = true;
                if (chkSexual.Content.ToString() == violenceForm.Form)
                    chkSexual.IsChecked = true;
                if (chkOthersViolenceForm.Content.ToString() == violenceForm.Form)
                    chkOthersViolenceForm.IsChecked = true;
            }
            var firstOrDefault = complaint.ViolenceForm.FirstOrDefault();
            if (firstOrDefault != null)
                tbDescription.Content = firstOrDefault.Description;
        }

        private void SetMultidisciplinaryTeam(Complaint complaint)
        {
            foreach (var multiTeam in complaint.MultidisciplinaryTeam)
            {
                if (chkMedic.Content.ToString() == multiTeam.Professional)
                    chkMedic.IsChecked = true;
                if (chkPsicology.Content.ToString() == multiTeam.Professional)
                    chkPsicology.IsChecked = true;
                if (chkSocialWorker.Content.ToString() == multiTeam.Professional)
                    chkSocialWorker.IsChecked = true;
                if (chkLegalAsessor.Content.ToString() == multiTeam.Professional)
                    chkLegalAsessor.IsChecked = true;
            }
        }

        private void SetCaseDerivations(Complaint complaint)
        {
            foreach (var caseDeriv in complaint.CaseDerivation)
            {
                if (chkDerivJudge.Content.ToString() == caseDeriv.Institution)
                    chkDerivJudge.IsChecked = true;
                if (chkDerivPublicMinistery.Content.ToString() == caseDeriv.Institution)
                    chkDerivPublicMinistery.IsChecked = true;
                if (chkDerivFELCC.Content.ToString() == caseDeriv.Institution)
                    chkDerivFELCC.IsChecked = true;
                if (chkDerivDefensory.Content.ToString() == caseDeriv.Institution)
                    chkDerivDefensory.IsChecked = true;
                if (chkDerivOther.Content.ToString() == caseDeriv.Institution)
                    chkDerivOther.IsChecked = true;
            }
        }

        private void LoadInformation()
        {
            var evidences = ComplaintDataAccess.GetAllEvidencesFromComplaint(ComplaintId);
            foreach (var evidence in evidences)
            {
                listBoxEvidences.Items.Add(evidence);
            }
            listBoxEvidences.UpdateLayout();
        }
    }
}
